#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>

using namespace std;

bool pon (int nepon) {
    if (nepon <= 1) return false;
    for (int i = 2; i * i <= nepon; i++) {
        if (nepon % i == 0) return false;
        }
    return true;
}
    
int samir (const string& za, const string& lu, const string& pa) {
    vector<string> qwerty = {"zего", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
    int zaq = find(qwerty.begin(), qwerty.end(), za) - qwerty.begin();
    int luq = find(qwerty.begin(), qwerty.end(), lu) - qwerty.begin();
    int paq = find(qwerty.begin(), qwerty.end(), pa) - qwerty.begin();
    return zaq * 100 + luq * 10 + paq;
}

int main() {
    string oi, za, pa, lu;
    getline(cin, oi);
    istringstream s(oi);
    s >> za >> pa >> lu;

    if (za == "zero" || pa == "zero" || lu == "zero") {
        cout << "wrong input" << endl;
        return 1;
    }

    int nepon = samir (za, pa, lu);
    if (nepon < 100 || nepon > 999) {
    cout << "Wrong input" << endl;
    return 1;
    }
    
    int m = nepon, b = nepon;
    while (true) {
        if (pon (m)) {
        cout << m << endl;
        return 0;
    }
        if (pon (b)) {
        cout << b << endl;
        return 0;
    }
    m--;
    b++;
}

return 0;

}
